package com.example.demo.controller;

import com.example.demo.entity.Course;
import com.example.demo.entity.Employee;
import com.example.demo.entity.MC;
import com.example.demo.entity.Member;
import com.example.demo.service.FitService;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("/api")
//@CrossOrigin(origins = "*")
public class FitController {

    private final FitService fs;

    public FitController(FitService fs) {
        this.fs = fs;
    }

    // 获取健身卡选项
    @GetMapping(value = "/cards")
    public ResponseEntity<List<Map<String, Object>>> getCardOptions() {
        return ResponseEntity.ok(fs.getCardOptions());
    }

    // 获取会籍选项
    @GetMapping(value = "/huijis")
    public ResponseEntity<List<Map<String, Object>>> getHuijiOptions() {
        return ResponseEntity.ok(fs.getHuijiOptions());
    }

    // 添加新会员
    @PostMapping("/members")
    public ResponseEntity<Void> addMember(@RequestBody Member member) {
        fs.addMember(member);
        return ResponseEntity.ok().build();
    }

    // 会员管理
    @GetMapping("/members")
    public ResponseEntity<List<Member>> getAllMembers() {
        return ResponseEntity.ok(fs.getAllMembers());
    }

    // 会员查询
    @GetMapping("/members/{memberNum}")
    public ResponseEntity<List<Member>> getMember(@PathVariable String memberNum) {
        return ResponseEntity.ok(fs.getMember(memberNum));
    }

    @DeleteMapping("/members/{memberNum}")
    public ResponseEntity<Void> deleteMember(@PathVariable String memberNum) {
        fs.deleteMember(memberNum);
        return ResponseEntity.ok().build();
    }

    @PutMapping("/members")
    public ResponseEntity<Member> updateMember(@RequestBody Member member) {
        fs.updateMember(member);
        return ResponseEntity.ok(member);
    }

    //添加报课表
    @PostMapping("/mc")
    public ResponseEntity<Void> addMC(@RequestBody MC mc) {
        fs.addMC(mc);
        return ResponseEntity.ok().build();
    }

    // 管理 获取报课信息
    @GetMapping("/MC")
    public ResponseEntity<List<MC>> getAllMC() {
        return ResponseEntity.ok(fs.getAllMC());
    }

    //删除报课记录  两个参数
    @DeleteMapping("/MC/{memberNum}/{courseNum}")
    public ResponseEntity<Void> deleteMC(@PathVariable String memberNum, @PathVariable String courseNum) {
        fs.deleteMC(memberNum, courseNum);
        return ResponseEntity.ok().build();
    }

    // 课程管理
    @GetMapping("/courses")
    public ResponseEntity<List<Course>> getAllCourses() {
        return ResponseEntity.ok(fs.getAllCourses());
    }

    // 添加课程
    @PostMapping("/courses")
    public ResponseEntity<Void> addCourse(@RequestBody Course course) {
        fs.addCourse(course);
        return ResponseEntity.ok().build();
    }

    // 单个课程号查询
    @GetMapping("/courses/{courseName}")
    public ResponseEntity<List<String>> getCourseNum(@PathVariable String courseName) {
        return ResponseEntity.ok(fs.getCourseNum(courseName));
    }

    // 单个课程删除
    @DeleteMapping("/courses/{courseNum}")
    public ResponseEntity<Void> deleteCourse(@PathVariable String courseNum) {
        fs.deleteCourse(courseNum);
        return ResponseEntity.ok().build();
    }

    // 教练员工管理
    @GetMapping("/employees/coaches")
    public ResponseEntity<List<Employee>> getCoaches() {
        return ResponseEntity.ok(fs.getCoaches());
    }

    @GetMapping("/employees/membership")
    public ResponseEntity<List<Employee>> getMembershipStaff() {
        return ResponseEntity.ok(fs.getMembershipStaff());
    }

    @PostMapping("/employees")
    public ResponseEntity<Employee> addEmployee(@RequestBody Employee employee) {
        fs.addEmployee(employee);
        return ResponseEntity.status(HttpStatus.CREATED).body(employee);
    }

    @PutMapping("/employees")
    public ResponseEntity<Employee> updateEmployee(@RequestBody Employee employee) {
        fs.updateEmployee(employee);
        return ResponseEntity.ok(employee);
    }

    @DeleteMapping("/employees/{eeNum}")
    public ResponseEntity<Void> deleteEmployee(@PathVariable String eeNum) {
        fs.deleteEmployee(eeNum);
        return ResponseEntity.ok().build();
    }


}